package com.farmUni.controller;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.farmUni.common.R;
import com.farmUni.entity.FoodRec;
import com.farmUni.service.FoodRecService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wxy
 * @since 2024-02-18
 */
@RestController
@RequestMapping("/foodRec")
public class FoodRecController {
    @Autowired
    private FoodRecService foodRecService;

    @GetMapping("/getRec")
    public R<List<FoodRec>> getRec(){
        return R.success(
                foodRecService.list(Wrappers.<FoodRec>lambdaQuery()
                        .orderByDesc(FoodRec::getScore)
                        .last("LIMIT 3"))
        );
    }
    @GetMapping("/getAll")
    public R<List<FoodRec>>getAll(){
        return R.success(
                foodRecService.list(Wrappers.<FoodRec>lambdaQuery()
                        .orderByDesc(FoodRec::getScore))
        );
    }
}

